package com.wkr.container;

import com.wkr.thread.wkrThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

@Component("mqContainter")
public class MqContainer {

    private static final Logger log = LoggerFactory.getLogger(MqContainer.class);
    /** 默认队列数量 */
    private static final int QUEUE_SIZE = 100000;

    private Queue queue = new ArrayBlockingQueue(QUEUE_SIZE);

    /** 线程池 */
    @Autowired
    private ThreadPoolTaskExecutor minaThreadPool;

    public void init() {
        /**
         * 用于自定义消息队列测试
         * wukangrong add
         */
        minaThreadPool.execute(new wkrThread(this));
        log.info("队列监听线程开启");
    }

    public Queue getQueue() {
        return this.queue;
    }

    public void setQueue(Queue queue) {
        this.queue = queue;
    }

    public void pushQueue(Object object) {
        queue.add(object);
    }

    public Object popQueue() {
        Object object = null;
        object = queue.poll();
        return object;
    }
}
